//#region 年月日 时分秒
let divnyr = document.getElementById('divnyr');
let divsfm = document.getElementById('divsfm');

// 获取年月日
let now = new Date();
// 分步获取时间
let year = now.getFullYear();
let month = now.getMonth() + 1;
let day = now.getDate();
divnyr.innerHTML = `${year}年${month}月${day}日`;

// 获取时分秒
let sfm = new Date();
// 分步获取时间
let hour = now.getHours();
let minute = now.getMinutes();
let second = now.getSeconds();
divsfm.innerHTML = `${hour}:${minute}:${second}`;

setInterval(() => {
  now = new Date();
  year = now.getFullYear();
  month = now.getMonth() + 1;
  day = now.getDate();
  divnyr.innerHTML = `${year}年${month}月${day}日`;
}, 1000);

setInterval(() => {
  hour = now.getHours();
  minute = now.getMinutes();
  second = now.getSeconds();
  divsfm.innerHTML = `${hour}:${minute}:${second}`;
}, 1000);

//#endregion

//#region 功能
let selyy = document.getElementById('selyy');
let selkm = document.getElementById('selkm');

const BASE_URL = 'https://api.huhuiyu.top';

function queryyy() {
  let promise = axios({
    url: BASE_URL + '/link/languages',
    method: 'get',
    data: '',
  });

  promise
    .then((resp) => {
      console.log(resp.data)
      let info = resp.data;
      if (!info.success) {
        alert(info.message);
        return;
      }
      //
      selyy.innerHTML = '';
      for (let i = 0; i < info.data.length; i++) {
        let pro = info.data[i];
        console.log(pro)
        let op = document.createElement('option');
        op.append(pro.lname);
        op.setAttribute('value', pro.plid);
        selyy.append(op);
      }
    })
    .catch((err) => {
      console.error(err);
    });
}

function querykm() {

  let promise = axios({
    url: `${BASE_URL}/link/cource/${selyy.value}`,
    method: 'get',
    data: '',
  }); 
  promise
    .then((resp) => {
      console.log(resp.data)
      let info = resp.data;
      if (!info.success) {
        alert(info.message);
        return;
      }
      for (let i = 0; i < info.data.length; i++) {
        let km = info.data[i];
        let opt = document.createElement('option');
        opt.append(km.cname);
        opt.setAttribute('value', km.lcid);
        selkm.append(opt);
      }
    })
    .catch((err) => {
      console.error(err);
    });
}

selyy.addEventListener('change', () => {
  querykm();
});

queryyy();

//#endregion
